package com.yutian.commandapp;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 整数计算
 *
 * @author zhoulei7
 * @create 2020-10-15
 **/
public class IntegerOper {

    private int i1;

    private int i2;

    public IntegerOper(int i1, int i2) {
        this.i1 = i1;
        this.i2 = i2;
    }

    public int add(){
        return i1 + i2;
    }

    public int subtract(){
        return i1 - i2;
    }

    public int multiply(){
        return i1 * i2;
    }

    public int divide(){
        return i1 / i2;
    }

    /**
     * 扩展
     * @param scale
     * @return
     */
    public String dividePrecise(int scale){
        return BigDecimal.valueOf(i1).divide(BigDecimal.valueOf(i2), scale, RoundingMode.HALF_UP).toPlainString();
    }
}
